package com.edu.chongdian;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

public class BalanceAdapter extends BaseAdapter {
    private Context mContext;
    private int[] mData;
    private int mSelectedPosition = -1;

    public BalanceAdapter(Context context, int[] data) {
        mContext = context;
        mData = data;
    }

    @Override
    public int getCount() {
        return mData.length;
    }

    @Override
    public Object getItem(int position) {
        return mData[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.chongzhi_item, parent, false);
        }

        TextView textView = convertView.findViewById(R.id.chongzhi);
        textView.setText(String.valueOf(mData[position]));
        textView.setBackgroundColor(Color.WHITE);
        if (position == mSelectedPosition) {
            textView.setBackgroundColor(Color.GREEN);
        } else {
            textView.setBackgroundColor(Color.WHITE);
        }
        return convertView;
    }
    public void setSelectedPosition(int position) {
        mSelectedPosition = position;
        notifyDataSetChanged();
    }
}
